﻿using LoveNote.Application.Share.Shell;
using LoveNote.Shell.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using TookKit.Mvvm.Attributes;
using TookKit.Mvvm.Bindings;
using TookKit.Mvvm.Enums;

namespace LoveNote.Shell.ViewModels
{
    [DependencyInjection(Lifetime.Singleton)]
    internal class DialogViewModel : ObservableObject
    {
        private MessageBoxButton messageBoxButton = MessageBoxButton.OK;
        public MessageBoxButton MessageBoxButton
        {
            get { return messageBoxButton; }
            set { SetProperty(ref messageBoxButton, value); } 
        }

        private string message = string.Empty;
        /// <summary>
        /// 消息提示
        /// </summary>
        public string Message
        {
            get { return message; }
            set { SetProperty(ref message, value); }
        }
        
        public ICommand LoadedCommand { get; }
        public ICommand UnloadedCommand { get; }
        public ICommand SubmitCommand { get; }
        public ICommand CancelCommand { get; }

        private Window Window { get; set; }
        public IShellManager ShellManager { get; set; }

        public DialogViewModel(IShellManager shellManager)
        {
            ShellManager = shellManager;
            LoadedCommand = new RelayCommand<Window>(OnLoadedCommand);
            UnloadedCommand = new RelayCommand(OnUnloadedCommand);
            SubmitCommand = new RelayCommand(OnSubmitCommand);
            CancelCommand = new RelayCommand(OnCancelCommand);
        }

        private void OnUnloadedCommand()
        {
            ShellManager.Hide();
        }

        private void OnLoadedCommand(Window window)
        {
            this.Window = window;
            ShellManager.Show();
        }

        private void OnSubmitCommand()
        {
            Window.DialogResult = true;
            Window.Close();
        }

        private void OnCancelCommand()
        {
            Window.DialogResult = false;
            Window.Close();
        }
    }
}
